<?php
/* 
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
echo "<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>";
echo "<response>";
session_start();
if ($_SESSION['kteam_auth'] != true)
{
    $expire=time()+60*60;
    setcookie("redirector", "ticket.html", $expire);
    echo "<result>Login</result>";
    echo "</response>";
    //header("Location: login.html");
    exit;
}

include("sqlconnect.php");
include("sqlgenerator.php");
$debug = false;

if ($debug) {
    echo '<debug>';
    echo 'Post parameters: ' . $_GET['producer_code'];
    echo '</debug>';
}

$ticket_rate = $_GET['ticket_rate'];
$action = $_GET['action'];

if (!is_null($action) && $action=='delete') {
    db_connect();
    $query = delete_ticketinfo($ticket_rate);
    if ($debug) {
        echo '<debug>';
        echo 'Query: ' . $query;
        echo '</debug>';
    }

    $result = db_query($query);
    echo "<result>Deleted</result>";
    exit;
}

db_connect();

// Query the film details from the film code
if (is_null($ticket_rate)) {
    $query = get_all_ticketinfos();
} else {
    $query = get_ticketinfo($ticket_rate);
}
if ($debug) {
    echo '<debug>';
    echo 'Query: ' . $query;
    echo '</debug>';
}
$result = db_query($query);
if ($debug) {
    echo '<debug>';
    echo 'Query Result: ' . $result;
    echo '</debug>';
}

while ($row = mysql_fetch_array($result)) {
    echo '<ticket>';
    try {
        echo '<ticket_id>'.$row['id'].'</ticket_id>';
        echo '<ticket_rate>'.$row['ticket_rate'].'</ticket_rate>';
        echo '<coupon_value>'.$row['coupon_value'].'</coupon_value>';
        echo '<l0>'.$row['l0'].'</l0>';
        echo '<l1>'.$row['l1'].'</l1>';
        echo '<l2>'.$row['l2'].'</l2>';
    } catch (Exception $e) {
        echo '</ticket>';
        echo "<result>Error</result>";
        echo "</response>";
    }
    echo '</ticket>';
}
echo "<result>Success</result>";
echo "</response>";

?>